

import Friend from "../model/Friend"

class FriendrViewModel{
  private friendList:Array<Friend>=[{name:"haha",phoneNumber:"kk"}];

  addFriend(newFriend:Friend):number{
    let result:number=this.queryFriend(newFriend);
    if (result===-1) {
      this.friendList.push(newFriend)
      return 1;
    }
    else {
      return 0
    }
  }
  queryFriend(qFriend:Friend):number {
    // this.userList.forEach(element => {
    //   if (element.account===qUser.account) {
    //     if (element.password===qUser.password) {
    //       return 1
    //     }
    //     else return 0
    //   }
    // });
    // return -1
    for (let item of this.friendList) {
      if (item.name===qFriend.name) {
         return 1;
      }
    }
    return -1;
  }
}
let friendViewModel=new FriendrViewModel();
export default friendViewModel as FriendrViewModel;